package com.platform.api;

import com.alibaba.fastjson.JSONObject;
import com.platform.entity.GroupPurchaseVo;
import com.platform.service.ApiGroupPurchaseService;
import com.platform.util.ApiBaseAction;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "拼团")
@RestController
@RequestMapping("/api/groupPurchase")
public class ApiGroupPurchaseController extends ApiBaseAction {
    private static final Logger logger = LoggerFactory.getLogger(ApiGroupPurchaseController.class);
    @Autowired
    private ApiGroupPurchaseService apiGroupPurchaseService;

    @ApiOperation(value = "查询所有拼团的商品")
    @PostMapping("list")
    public Object list() {
        logger.info("【请求开始】查询所有拼团的商品,无请求参数");

        List<GroupPurchaseVo> groupPurchaseVos = apiGroupPurchaseService.queryList(null);

        logger.info("【请求结束】查询所有拼团的商品,响应结果:{}",groupPurchaseVos);
        return this.toResponsDateSuccess(groupPurchaseVos);
    }

    @ApiOperation(value = "拼团商品详情")
    @PostMapping("detail")
    public Object detail() {
        JSONObject jsonObject = this.getJsonRequest();
        logger.info("【请求开始】拼团商品详情,无请求参数"+jsonObject);

        Integer id =jsonObject.getInteger("id");
        GroupPurchaseVo groupPurchase = apiGroupPurchaseService.queryObject(id);

        logger.info("【请求结束】查询所有拼团的商品,响应结果:{}",groupPurchase);
        return this.toResponsDateSuccess(groupPurchase);
    }
}
